import { DictValueEnum } from "@/components/DictTag";
import { getInfo } from "@/services/api/module/tenant/storage/file";
import { ProDescriptions } from "@ant-design/pro-components";
import { Image, Modal, Typography } from "antd";
import React, { useEffect, useState } from "react";
export type OssConfigDetailsProps = {
	onCancel: () => void;
	open: boolean;
	fileType: DictValueEnum;
	id: undefined | string | number;
	dataSource: API.Setting.StorageFileVo | undefined;
	// statusOptions: DictValueEnumObj;
};
const FileDetails: React.FC<OssConfigDetailsProps> = ({
	onCancel = () => {},
	open = false,
	id,
	dataSource
	// statusOptions,
	// accessPolicyOptions,
}) => {
	const [previewData, setPreviewData] = useState<any>(undefined);
	// 请求数据
	const getDetailData = (id: any) => {
		getInfo(id).then(res => {
			setPreviewData(res.data);
		});
	};
	useEffect(() => {
		if (id) {
			getDetailData(id);
		}
	}, [id]);

	return (
		<>
			<Modal title="详情" width="50%" centered onCancel={onCancel} open={open}>
				<div
					style={{
						display: "flex",
						alignItems: "center",
						justifyContent: "center",
						height: "250px",
						background: "#f5f5f5",
						marginBottom: "10px"
					}}
				>
					{dataSource?.fileType === "img" && <Image style={{ maxHeight: "250px", maxWidth: "100%" }} src={dataSource?.url} />}

					{dataSource?.fileType !== "img" && <Typography>当前格式不支持预览。</Typography>}
				</div>
				<div>
					<ProDescriptions
						bordered
						columns={[
							{
								title: "文件名",
								key: "fileName",
								dataIndex: "fileName"
							},
							{
								title: "原名",
								key: "originalName",
								dataIndex: "originalName"
							},
							{
								title: "文件大小",
								key: "fileSize",
								dataIndex: "fileSize"
							},
							{
								title: "文件类型",
								key: "fileMime",
								dataIndex: "fileMime"
							},
							{
								title: "文件分类",
								key: "fileType",
								dataIndex: "fileType"
							},
							{
								title: "服务商",
								key: "service",
								dataIndex: "service"
							},
							{
								title: "上传人",
								key: "createByName",
								dataIndex: "createByName"
							},
							{
								title: "上传时间",
								key: "createTime",
								dataIndex: "createTime"
							},
							{
								title: "链接",
								key: "url",
								dataIndex: "url",
								copyable: true
							}
						]}
						emptyText="空"
						column={1}
						dataSource={dataSource}
					/>
				</div>
			</Modal>
		</>
	);
};

export default FileDetails;
